package com.lili.math;

import java.util.*;

/**
 * @Auther: 李 力
 * @Date: 2024/8/19
 * @Description: 强整数
 * @version: 1.0
 */
public class LeetCode970 {

    /*
     *  时间复杂度：O(log^2bound)
     *  空间复杂度：O(log^2bound)
     *
     * */
    public List<Integer> powerfulIntegers(int x, int y, int bound) {
        Set<Integer> list = new HashSet<>();
        int value1 = 1;
        for (int i = 0; i < 21; i++) {
            int value2 = 1;
            for (int j = 0; j < 21; j++) {
                int value = value1 + value2;
                if (value <= bound) {
                    list.add(value);
                } else {
                    break;
                }
                value2 = value2 * y;
            }
            if (value1 > bound) {
                break;
            }
            value1 = value1 * x;
        }
        return new ArrayList<>(list);
    }
}
